package com.woniu.controller;

import com.woniu.entity.PageData;
import com.woniu.entity.Result;
import com.woniu.entity.dto.QueryBerthDTO;
import com.woniu.pojo.Berth;
import com.woniu.pojo.Inspector;
import com.woniu.pojo.Road;
import com.woniu.service.BerthService;
import com.woniu.utils.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "泊位管理")
@RestController
@RequestMapping("/berth")
@CrossOrigin
public class BerthController extends BaseController {

    @Autowired
    private BerthService berthService;


    @ApiOperation("搜索+分页")
    @PostMapping("/list/search/{currentPage}/{pageSize}")
    public Result listSearch(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody(required = false) QueryBerthDTO queryBerthDTO){
        PageData pageData =  berthService.listSearch(currentPage, pageSize, queryBerthDTO);
        return toDataResult(pageData);
    }

    @ApiOperation("新增或者修改")
    @PostMapping
    public Result saveOrUpdate(@RequestBody Berth berth){
        boolean flag = berthService.saveOrUpdate(berth);
        return toResult(flag);
    }

    @ApiOperation("删除操作")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable String id){
        boolean flag = berthService.removeById(id);
        return toResult(flag);
    }

    @ApiOperation("根据ID查询")
    @GetMapping("/{id}")
    public Result getById(@PathVariable String id){
        Berth berth = berthService.getById(id);
        return toDataResult(berth);
    }

    @ApiOperation("根据ID查询路段名")
    @GetMapping("/road/{id}")
    public Result getByRoadName(@PathVariable String id){
        Road road = berthService.getByRoadName(id);
        return toDataResult(road);
    }
}
